<template>
	<view>
		<scroll-view scroll-y="true" style="height: 1000rpx;">
				<view class="popupBox">
						<view class="title">
							起始路线
						</view>
						<view class="path-box">
							<view class="origin" @click="setShowUniAddressSelector('start')">
								{{areaInfoStartObj.fullAreaTextInitial||'起点'}}
							</view>
							<view class="line">
				
							</view>
							<view class="destination" @click="setShowUniAddressSelector('end')">
								{{areaInfoEndObj.fullAreaTextInitial||'终点'}}
							</view>
						</view>
						<view class="title">
							宠物类型
						</view>
						<view class="tag-box">
							<view class="tag-item" :class="{'active-item':item.active}" @click="setActive(item)"  v-for="item in brandList">
								{{item.name}}
							</view>
						</view>
						<view class="title">
							宠物数量
						</view>
						<view class="tag-box">
							<view class="tag-item" :class="{'active-item':amountIndex===index}" @click="setAmountIndex(index)" v-for="(item, index) in amountList">
								{{item.text}}
							</view>
						</view>
						<view class="title">
							选择笼具大小
						</view>
						<view class="form-item_box" v-for="item in cageList">
							<view class="select-box" :class="{'select-box-active':item.active}"  @click="setActive(item)">
				                   <u-icon name="checkbox-mark" color="#ffffff"></u-icon>
							</view>
							<view class=""
								style="flex: 1;font-size: 28rpx;color: #333333;font-weight: bold;margin-left: 16rpx;">
								{{item.name}}
							</view>
							<u-number-box v-model="item.cageNumber" :min="0" buttonSize="46rpx"></u-number-box>
						</view>
					    <view class="title">
					    	价格区间（元）
					    </view>
						<view class="money-box">
							<view class="money">
								<input type="number" v-model="startMoney">
							</view>
							<view class="line">
								
							</view>
							<view class="money">
								<input type="number"  v-model="endMoney">
							</view>
						</view>
						<view class="title">
							日期区间
						</view>
						<view class="date-box">
							<view class="date" @click="calendarShow=true">
								{{startDate||'请选择'}}
							</view>
							<view class="line">
								
							</view>
							<view class="date" @click="calendarShow=true">
								{{endDate||'请选择'}}
							</view>
						</view>
						
				
						<view class="btn-box">
							<view class="" @click="reset">
								重置
							</view>
							<view class="" @click="submit">
								确定
							</view>
						</view>
					</view>
				<UniAddressSelector v-if="showUniAddressSelector" :areaInfoSelected="areaInfoObj" @cancel="handleCancel"
					@confirm="handleConfirm">
				</UniAddressSelector>
				
				<u-calendar :show="calendarShow" mode="range" color="#FFCE4E" @confirm="confirm" @close="close" showLunar monthNum="6"></u-calendar>
			</scroll-view>
	</view>
</template>

<script>
	import UniAddressSelector from '@/components/UniAddressSelector/UniAddressSelector.vue'
	let pathType=null
	export default {
		components: {
			UniAddressSelector
		},
		data() {
			return {
				showUniAddressSelector:false,
				areaInfoObj: {},
				areaInfoStartObj:{
					provinceObj: {
						areaCode: '',
						areaName: '',
					},
					cityObj: {
						areaCode: '',
						areaName: '',
					},
					areaObj: {
						areaCode: '',
						areaName: '',
					},
					fullAreaTextInitial: ''
				},
				areaInfoEndObj:{
					provinceObj: {
						areaCode: '',
						areaName: '',
					},
					cityObj: {
						areaCode: '',
						areaName: '',
					},
					areaObj: {
						areaCode: '',
						areaName: '',
					},
					fullAreaTextInitial: ''
				},
				cageList:[],
				calendarShow:false,
				startDate:'',
				endDate:'',
				startMoney:'',
				endMoney:'',
				brandList:[],
				amountList:[{
					text:'1',
					value:1
				},{
					text:'2',
					value:2
				},{
					text:'3-5',
					value:90
				},{
					text:'5-10',
					value:91
				},{
					text:'>10',
					value:92
				}],
				amountIndex:-1
			}
		},
		mounted() {
			this.$myRequest('/api/user/home/v1/cage').then(res=>{
				let data=res.data||[]
				data.forEach(item=>{
					item.active=false
					item.cageNumber=0
				})
				this.cageList=data
			})
			
			
			this.$myRequest('/api/user/mine/v1/petCate/options', {
				level: 1
			}).then(res => {
				let data=res.data||[]
				data.forEach(item=>{
					item.active=false
				})
				this.brandList= data
			})
		},
		methods: {
			reset(){
				this.areaInfoEndObj={}
				this.areaInfoStartObj={}
				this.endDate=''
				this.startDate=''
				this.startMoney=''
				this.endMoney=''
				this.amountIndex=-1
				this.cageList.forEach(item=>{
					item.active=false
					item.cageNumber=0
				})
				this.brandList.forEach(item=>{
					item.active=false
				})
				this.submit()
			},
			setAmountIndex(index){
				this.amountIndex=this.amountIndex===index?-1:index
			},
			confirm(e) {
				this.startDate=e[0]
				this.endDate=e[e.length-1]
				this.close()
			},
			close(){
				this.calendarShow=false
			},
			setActive(item){
				console.log(item.active)
				item.active=!item.active
			},
			setShowUniAddressSelector(type){
				pathType=type
				if(pathType=='start'){
					this.areaInfoObj =this.areaInfoStartObj;
				}else{
					this.areaInfoObj = this.areaInfoEndObj;
				}
				this.showUniAddressSelector = true;
			},
			handleCancel() {
				this.showUniAddressSelector = false;
			},
			handleConfirm(areaInfoObj) {
				this.showUniAddressSelector = false;
				if(pathType=='start'){
					this.areaInfoStartObj = areaInfoObj;
				}else{
					this.areaInfoEndObj = areaInfoObj;
				}
			},
			submit(){
				let data={
					endAreaCode:this.areaInfoEndObj.areaObj?this.areaInfoEndObj.areaObj.areaCode:'',
					startAreaCode:this.areaInfoStartObj.areaObj?this.areaInfoStartObj.areaObj.areaCode:'',
					endDate:this.endDate?this.endDate+' 23:59:59':'',
					startDate:this.startDate?this.startDate+' 00:00:00':'',
					priceDistance:this.startMoney?`${this.startMoney}-${this.endMoney}`:'',
					petCount:this.amountIndex!==-1?this.amountList[this.amountIndex].value:''
				}
				let cageChooseList=[]
				this.cageList.forEach(item=>{
					if(item.active){
						cageChooseList.push({
							cageId:item.id,
							cageNumber:item.cageNumber
						})
					}
				})
				data.cageChooseList=cageChooseList
				
				let categoryIdList=[]
				this.brandList.forEach(item=>{
					if(item.active){
						categoryIdList.push(item.id)
					}
				})
				data.categoryIdList=categoryIdList
				console.log('导出数据',data)
				this.$emit('submit',data)
				
			},
		}
	}
</script>

<style lang="scss">
	.popupBox {
		padding: 40rpx 20rpx;

		.title {
			font-size: 28rpx;
			color: #333333;
			font-weight: 700;
			position: relative;
			padding-left: 20rpx;

			&:before {
				content: '';
				width: 12rpx;
				height: 24rpx;
				position: absolute;
				left: 0;
				top: 50%;
				transform: translateY(-50%);
				background: $theme-color;
			}
		}

		.path-box {
			display: flex;
			flex-direction: column;
			align-items: center;
			margin: 20rpx 0;

			.origin,
			.destination {
				border-radius: 8rpx;
				text-align: center;
				font-size: 28rpx;
				font-weight: bold;
				// line-height: 82rpx;
				color: #1C1C1C;
				padding: 20rpx;
				min-width: 300rpx;
			}

			.origin {
				background: rgba(72, 212, 242, .19);

			}

			.line {
				width: 2rpx;
				height: 32rpx;
				background-color: #CBCBCB;
				margin: 22rpx auto;
			}

			.destination {

				background: rgba(254, 206, 99, .19);
			}
		}


		.form-item_box {
			display: flex;
			align-items: center;
			padding: 20rpx;
		}

		.select-box {
			width: 40rpx;
			height: 40rpx;
			border-radius: 14rpx;
			background-color: #DCDCDC;
			display: flex;
			align-items: center;
			justify-content: center;
		}

		.select-box-active {
			background-color: $theme-color;
		}
		.tag-box{
			display: flex;
			flex-wrap: wrap;
			padding: 20rpx;
			.tag-item{
				padding: 12rpx 36rpx;
				background-color: rgba(203, 203, 203, 0.20);
				border-radius: 10rpx;
				border: 2rpx solid #CBCBCB;
				font-size: 28rpx;
				color: #999999;
				margin-right: 20rpx;
			}
			.active-item{
				background-color: rgba(254, 175, 172, 0.20);
				border: 2rpx solid #FEAFAC;
				color: #FEAFAC;
			}
		}
	
	    .money-box{
			display: flex;
			align-items: center;
			padding: 20rpx 40rpx;
			.money{
				padding: 20rpx;
				border-radius: 12rpx;
				background-color: #f5f5f5;
			}
			.line{
				width: 30rpx;
				height: 2rpx;
				background-color: #f5f5f5;
				margin: 0 20rpx;
			}
		}
		.date-box{
			display: flex;
			align-items: center;
			padding: 20rpx 40rpx;
			text-align: center;
			color: #999999;
			font-size: 28rpx;
			.date{
				padding: 20rpx 0;
				flex: 1;
				border-radius: 12rpx;
				background-color: #f5f5f5;
			}
			.line{
				width: 30rpx;
				height: 2rpx;
				background-color: #f5f5f5;
				margin: 0 20rpx;
			}
		}
	
	     .btn-box{
			 display: flex;
			 width: 600rpx;
			 height: 80rpx;
			 line-height: 80rpx;
			 border-radius: 80rpx;
			 text-align: center;
			 overflow: hidden;
			 margin: 40rpx auto;
			 view{
				 flex: 1;
			 }
			 view:nth-child(1){
				background-color: #EBECEE;
				color: #666666;
			 }
			 view:nth-child(2){
			 	background: $theme-color;
				color: #ffffff;
			 }
		 }
	}

</style>
